package com.investment.advisor.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Table(name = "factors")
@Getter
@Setter
@NoArgsConstructor
@ToString(exclude = {"strategyFactors"})
public class Factor {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 100)
    private String name;

    @Column(length = 50)
    private String category;  // 因子分类：基本面、技术、估值、流动性等

    @Column(length = 1000)
    private String description;  // 因子描述

    @Column(length = 255)
    private String formula;  // 因子计算公式

    @Column(precision = 10, scale = 4)
    private BigDecimal weight;  // 默认权重

    @Column(length = 100)
    private String creator;  // 创建者

    @JsonManagedReference
    @OneToMany(mappedBy = "factor")
    private Set<StrategyFactor> strategyFactors;  // 使用该因子的策略及权重

    @CreationTimestamp
    private LocalDateTime createTime;

    @UpdateTimestamp
    private LocalDateTime updateTime;
} 